package com.office.meetingManage.meeting.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.office.meetingManage.meeting.dao.IMetingDao;
import com.office.meetingManage.meeting.model.*;
import com.office.meetingManage.meeting.service.IMeetingService;
import com.office.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class MeetingService implements IMeetingService {


    @Autowired
    private IMetingDao metingDao;

    public IMetingDao getMetingDao() {
        return metingDao;
    }

    public void setMetingDao(IMetingDao metingDao) {
        this.metingDao = metingDao;
    }

    //查询会议信息
    @Override
    public List<MeetingMessage> getMeetingMessage(MeetingMessageCondition meetingMessageCondition) {
        return metingDao.getMeetingMessage(meetingMessageCondition);
    }

    //分页查询会议信息
    @Override
    public PageModel<MeetingMessage> getMeetingMessage(MeetingMessageCondition meetingMessageCondition, PageModel<MeetingMessage> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize() <= 0 ? 4 : pageModel.getPageSize());
        PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());
        List<MeetingMessage> backList = metingDao.getMeetingMessage(meetingMessageCondition);


        PageInfo<MeetingMessage> pageInfo = new PageInfo<MeetingMessage>(backList);

        pageModel.setData(new ArrayList<MeetingMessage>(backList));
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageInfo.getTotal());
        return pageModel;
    }

    //查询员工id和姓名

    public List<staff> getStaffMessage(){
        return metingDao.getStaffMessage();
    }

    //查询会议室id和会议室名
    public List<meetingRoom> getMeetingRoom(){
        return metingDao.getMeetingRoom();
    }

    //添加会议信息

    public boolean addMeetingMessage(MeetingMessage meetingMessage){
        boolean b = metingDao.addMeetingMessage(meetingMessage);
        return b;
    }

    //添加参会人员

    public boolean addAttendStaff(attend attend){
        boolean b = metingDao.addAttendStaff(attend);
        return b;
    }

    //向员工发送会议信息
    public boolean addOnlineMessage(OaOnlineMessage oaOnlineMessage){
        boolean b = metingDao.addOnlineMessage(oaOnlineMessage);
        return b;
    }

    //修改会议室状态
    public boolean updateMeetRoomStatus(MeetingMessage meetingMessage){
        boolean b = metingDao.updateMeetRoomStatus(meetingMessage);
        return b;
    }

    //修改会议信息

    public boolean updateMeetingMessage(MeetingMessage meetingMessage){
        boolean b = metingDao.updateMeetingMessage(meetingMessage);
        return b;
    }

    //删除会议信息
    public boolean deleteMeetingMessage(MeetingMessageCondition meetingMessageCondition){
        boolean b = metingDao.deleteMeetingMessage(meetingMessageCondition);
        return b;
    }

    //删除参加会议的参会人

    public boolean deleteAttend(MeetingMessageCondition meetingMessageCondition){
        boolean b = metingDao.deleteAttend(meetingMessageCondition);
        return b;
    }

    //删除发送的信息

    public boolean deleteMessage(MeetingMessageCondition meetingMessageCondition){
        boolean b = metingDao.deleteMessage(meetingMessageCondition);
        return b;
    }
    //添加会议记录
    public boolean addOaRecord(OaRecord oaRecord){
//        boolean  b =false;
//        List<OaRecord> oaRecords = metingDao.checkOaRecord(oaRecord);
//        if (oaRecords.size()==0){//查询是否存在该会议的记录
        boolean  b = metingDao.addOaRecord(oaRecord);//不存在则添加
//        }

        return b;
    }

    //查询会议记录是否已存在
    public List<OaRecord> checkOaRecord(OaRecord oaRecord){
        List<OaRecord> oaRecords = metingDao.checkOaRecord(oaRecord);
        return oaRecords;
    }

    //查询会议内容
    public RecordMessage checkRecordMessage(OaRecord oaRecord){
        RecordMessage recordMessage = metingDao.checkRecordMessage(oaRecord);
        return recordMessage;
    }

    //查询个人会议安排
    public List<PersonalArrangement> checkPersonalArrangement(staff staff){
        return metingDao.checkPersonalArrangement(staff);
    }

    //查看留言信息
    public List<MessageArrangement> checkMessageArrangement(staff staff){
        return metingDao.checkMessageArrangement(staff);
    }

    //查看日程安排


    public List<WorkArrangement> checkWorkArrangement(staff staff){
        List<WorkArrangement> workArrangements = metingDao.checkWorkArrangement(staff);
        return workArrangements;
    }

    //修改留言 已读

    public boolean updateMessageArrangement(MessageArrangement messageArrangement){
        boolean b = metingDao.updateMessageArrangement(messageArrangement);
        return b;
    }


    //修改参会状态 已参会

    public boolean updatePersonalArrangement(PersonalArrangement personalArrangement){
        boolean b = metingDao.updatePersonalArrangement(personalArrangement);
        return b;
    }

    //删除留言信息安排任务
    public boolean deleteMessageArrangement(MessageArrangement messageArrangement){
        boolean b = metingDao.deleteMessageArrangement(messageArrangement);
        return b;
    }

    //删除会议安排任务
    public boolean deletePersonalArrangement(PersonalArrangement personalArrangement){
        return metingDao.deletePersonalArrangement(personalArrangement);
    }


    //修改日程安排 已完成
    public boolean updateWorkArrangement(WorkArrangement workArrangement){
        boolean b = metingDao.updateWorkArrangement(workArrangement);
        return b;
    }

    //删除日程安排任务
    public boolean deleteWorkArrangement(WorkArrangement workArrangement){
        return metingDao.deleteWorkArrangement(workArrangement);
    }

}
